/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.facebook.fresco.samples.showcase.list;

import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.fresco.samples.showcase.ResourceTable;
import com.oszc.bbhmlibrary.utils.LogUtil;
import ohos.agp.components.BaseItemProvider;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

import java.util.ArrayList;

public class ListViewProvider extends BaseItemProvider {
    private final String TAG = ListViewProvider.class.getSimpleName();
    private ArrayList<String> listItems;
    String uristring;

    public ListViewProvider(ArrayList<String> listItems) {
        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int i) {
        return listItems.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        SimpleDraweeView simpledrawee = null;
        if (component == null) {
            component = LayoutScatter.getInstance(componentContainer.getContext()).parse(ResourceTable.Layout_imagelist,null,false);
            simpledrawee = (SimpleDraweeView) component.findComponentById(ResourceTable.Id_simpledraweeview_listview_01);
            component.setTag(simpledrawee);

        }else{
            simpledrawee = (SimpleDraweeView) component.getTag();
        }

        simpledrawee.setImageURI(listItems.get(i%listItems.size()));
        uristring = listItems.get(i%listItems.size());
        LogUtil.error(TAG,"getComponent i:"+i+"   url:"+uristring);

        /*TC_HMOSLIB_Freasco_Stablity_005
        Uri uriimage = Uri.parse(uristring);
        final ImageRequest imageRequest =
                ImageRequestBuilder.newBuilderWithSource(uriimage)
                        .setResizeOptions(ResizeOptions.forDimensions(64,64))
                        .setImageDecodeOptions(new ImageDecodeOptionsBuilder().build())
                        .build();

        final DraweeController draweeController =
                Fresco.newDraweeControllerBuilder()
                        .setOldController(simpledrawee.getController())
                        .setImageRequest(imageRequest)
                        .build();
        simpledrawee.setController(draweeController);*/

        /*TC_HMOSLIB_Freasco_Stablity_003, TC_HMOSLIB_Freasco_Stablity_004
        RotationOptions rotationOptions01 = RotationOptions.forceRotation(RotationOptions.ROTATE_90);
        Uri uriimage = Uri.parse(uristring);
        ImageRequest imageRequest =
                ImageRequestBuilder.newBuilderWithSource(uriimage).setRotationOptions(rotationOptions01).build();
        simpledrawee.setImageRequest(imageRequest);*/





   /*     RoundingParams roundparams = RoundingParams.fromCornersRadius(100);
        roundparams.setBorder(Color.RED.getValue(), 10.0f);
        simpledrawee.getHierarchy().setRoundingParams(roundparams);*/


        return component;
    }


  /*  private void TC_HMOSLIB_Freasco_Stablity_001(SimpleDraweeView simpledrawee) {
        RoundingParams roundparams = RoundingParams.fromCornersRadius(100);
        roundparams.setBorder(Color.RED.getValue(), 10.0f);
        simpledrawee.getHierarchy().setRoundingParams(roundparams);
    }

    private void TC_HMOSLIB_Freasco_Stablity_003(SimpleDraweeView simpledrawee) {
        RotationOptions rotationOptions01 = RotationOptions.forceRotation(RotationOptions.ROTATE_90);
        // rotationOptions01.getForcedAngle();
        // rotationOptions01.canDeferUntilRendered();

        Uri uriimage = Uri.parse(uristring);
        ImageRequest imageRequest =
                ImageRequestBuilder.newBuilderWithSource(uriimage).setRotationOptions(rotationOptions01).build();
        simpledrawee.setImageRequest(imageRequest);

        simpledrawee.setImageRequest(imageRequest);

        LogUtil.info("Get Method", "Forced rotation angle: " +rotationOptions01.getForcedAngle()
                + "Rotation enabled: " + rotationOptions01.rotationEnabled() + "Can user defined: " + rotationOptions01.canDeferUntilRendered());
    }*/



}
